package com.lq.JDBC;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.Test;

import java.sql.SQLException;

public class TestHiKari {
    @Test
    public void getConnection() throws SQLException {
        // 创建数据源
        HikariDataSource dataSource = new HikariDataSource();
        // 配置数据源
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/jdbc_test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true&cachePrepStmts=true");
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        System.out.println(dataSource.getConnection());
    }

    @Test
    public void getConnection2() throws SQLException {
        HikariConfig hikariConfig = new HikariConfig("hikari.properties");
        HikariDataSource hikariDataSource = new HikariDataSource(hikariConfig);
        System.out.println(hikariDataSource.getConnection());
    }

}
